﻿#Include ..\baseHandle.ahk

#Include ..\..\_lib\ExecAhk2Script.ahk
#Include ..\..\_lib\Path.ahk

class Use extends BaseHandle {

  static Handle(parsed) {
    t := parsed.target
    if Path.IsAbsolute(t) && FileExist(t) {
      ExecScript(t, , parsed.Extra.Join(A_Space))
      return this.Succ('ok', 'x')
    }
    cfs := MeowConf.Of('.\cfg\useFile.txt')
    if !r := cfs.Get(t)
      return this.Fail(t ' not found')
    if parsed.hasParam('v') {
      return this.Succ(r)
    }
    Run(r) ; TODO: 传递运行参数
    return this.Succ('ok(mcf)', 'x')
  }


  static Spec() {
    return {
      cmd: 'use',
      desc: '运行脚本',
      format: 'use <target> [extra...]',
      params: [{
        name: 'v',
        desc: '返回配置的路径'
      }],
      args: {
        desc: '配置项或脚本路径',
        isOptional: false,
        cacheable: true,
        fixed: false,
        generator: {
          script: '',
          postProcess: (*) => MeowConf.Of('./cfg/useFile.txt').data.keys
        }
      },
      extra: {
        isEnable: true,
        isMulti: true,
        desc: '脚本运行参数'
      }
    }
  }
}